package com.springMVCStudy.json;

import com.springMVCStudy.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

//@Controller
@RequestMapping("/json")
// 加了@ResponseBody注解，数据直接放入响应体返回，不会走视图解析器，快速查找视图、重定向和转发也不生效了！
//@ResponseBody
// @RestController = @Controller + @ResponseBody
@RestController
public class JsonController {

    @GetMapping("/data")
    public User data() {
        User user = new User("gouzi", 11);
        System.out.println(user);
        // user -> handlerAdapter -> json -> @ResponseBody -> json直接返回（前后端分离模式）
        return user;
    }

    @GetMapping("/data1")
    public List<User> data1() {
        List<User> users = new ArrayList<User>();
        users.add(new User("mimimi", 3));
        users.add(new User("fffff", 5));
        System.out.println(users);
        return users;
    }


}
